<?php
	class List_model extends Model{
		function List_model(){
			parent::Model();
		}
        
        function getData($field, $tabel, $where='',$group_by='') {
            $this->db->select($field);
            if ($where!='') {
                $this->db->where($where);
            }
            if ($group_by!='') {
                $this->db->group_by($group_by);
            }
            $query = $this->db->get($tabel);
            if ($query->num_rows() > 0) {
                if ($row = $query->row_array()) {
                    return $row[$field];
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        
        
        
        function list_user($where="", $num=0, $offset=0, $ro=false) {
            
            $this->db->from('user');
             
            
            if ($where!='') {
                $this->db->where($where);
            }
            
            if ($num > 0) {
                $this->db->limit($num, $offset);
            }
            $query = $this->db->get();
            $s = "
              <table align=\"center\" cellspacing=\"1\" cellpadding=\"2\" class=\"tbl\">
                <tbody>
                  <tr>
                    <th class='number'>No</th>
                    <th>Nama</th>
                    <th>Nama Lengkap</th>
			        <th>Grup</th>                    

                    ";
            if ($ro==false) {
                $s .= " <th > Status </th>
                        <th colspan='2'> Aksi </th>";
            }

            $s .= "</tr>
            ";
            if ($num > 0) {
                $i = ($num * ($offset/$num)) + 1;
            } else {
                $i = 1;
            }

            
            
            foreach ($query->result() as $row) {
                
                
                if ($i % 2 == 1 ) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }

                $status = $row->aktif; 
                
                if ($status == 1 )
                    $status = "Aktif";
                else
                    $status = "Tidak Aktif";
                    
                $grup = $this->getData('nama', 'grup', 'idctk_grup = '.$row->id_grup.'');
                              
                $s .= "
              <tr class=\"$kelas\">
                
                <td><div align=\"right\">$i.</div></td>                
                <td><div>".$row->namauser."</div></td>
                <td><div>".$row->nama_lengkap."</div></td>
                <td><div align=\"center\">$grup</div></td>
                
                ";
                if ($ro==false) {
                    $s .= "

                    <td><div align=\"center\">$status</div></td>
                    <!--<td><div align=\"center\"><input type=\"checkbox\" id=\"".$row->namauser."\" value=\"".$row->namauser."\" /></div></td>-->
                    <td><div align='center'> <a href='".base_url()."index_arsip.php/main_user/edit_user/".$row->namauser."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>   
                    <td><div align='center'> <a href=\"javascript:deleteRow('".$row->namauser."')\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
                    
                }
                $s .= "
              </tr>";

                $i++;
            }
            $s .= "</table>";
            return $s;
        }

        
        
        function list_grup($where="", $num=0, $offset=0, $ro=false) {
            
            $this->db->from('grup');
             
            
            if ($where!='') {
                $this->db->where($where);
            }
            
            if ($num > 0) {
                $this->db->limit($num, $offset);
            }
            $query = $this->db->get();
            $s = "
              <table align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" class=\"tbl\">
                <tbody>
                  <tr>
                    <th class='number'>No</th>
                    <th>Nama Grup</th>                    

                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }

            $s .= "</tr>
            ";
            if ($num > 0) {
                $i = ($num * ($offset/$num)) + 1;
            } else {
                $i = 1;
            }

 
            foreach ($query->result() as $row) {
                
                
                if ($i % 2 == 1 ) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
  
                              
                $s .= "
              <tr class=\"$kelas\" id=\"row-".$row->idctk_grup."\" >
                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
                <td><div>".$row->nama."</div></td>

                
                ";
                if ($ro==false) {
                    $s .= "

                   <!-- <td><div align=\"center\"><input type=\"checkbox\" id=\"".$row->idctk_grup."\" value=\"".$row->idctk_grup."\" /></div></td> -->
                    <td><div align='center'> <a href='".base_url()."index_arsip.php/main_user/edit_grup/".$row->idctk_grup."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>   
                    <td><div align='center'><!--<a href=\"javascript:konfirmasi(".$row->idctk_grup.")\" title=\"Hapus Data\" class=\"delete\"> --> <a href=\"javascript:deleteRow(".$row->idctk_grup.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
                    
                    
                }
                $s .= "
              </tr>";

                $i++;
            }
            $s .= "</table>";
            return $s;
        }
    
        
	}
?>